package com.crm;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

public class CodeGenerator {


    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:p6spy:mysql://8.155.194.248:3306/gnlhkj_m2c?autoReconnect=false&useSSL=false&connectTimeout=3000&rewriteBatchedStatements=true&allowMultiQueries=true&socketTimeout=20000&clobberStreamingResults=true&netTimeoutForStreamingResults=0&failOverReadOnly=false&readOnlyPropagatesToServer=false&characterEncoding=utf8", "gnlh_root", "gnlh#@54231lskajf")
                .globalConfig(builder -> {
                    builder.author("zhangzhen") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .outputDir("D://code1"); // 指定输出目录
                })
                .dataSourceConfig(builder ->
                        builder.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> {
                            int typeCode = metaInfo.getJdbcType().TYPE_CODE;
//                            if (typeCode == Types.SMALLINT) {
//                                // 自定义类型转换
//                                return DbColumnType.INTEGER;
//                            }
                            return typeRegistry.getColumnType(metaInfo);
                        })
                )
                .packageConfig(builder ->
                        builder.parent("com.guangnian.crm") // 设置父包名
                                .entity("entity") // 设置实体类包名
                                .mapper("mapper") // 设置 Mapper 接口包名
                                .service("service") // 设置 Service 接口包名
                                .serviceImpl("service.impl") // 设置 Service 实现类包名
                                .xml("mapper") // 设置 Mapper XML 文件包名
                                .pathInfo(Collections.singletonMap(OutputFile.xml, "D://")) // 设置mapperXml生成路径
                ).templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .strategyConfig(builder -> {
                    builder.addInclude("company").entityBuilder().enableLombok()
                            .enableTableFieldAnnotation()
                            .controllerBuilder()
                            .enableRestStyle();
                })
                .execute();
    }
}
